package user;

import utils.EmailSender;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "TestEmailServlet")
public class TestEmailServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        sendmail("850476264@qq.com");
    }

    private boolean sendmail(String mailto){
        String MailTo=mailto;
        String MailSubject="测试";
        String MailBCopyTo="";
        String MailCopyTo="";
        String MailBody="<p></p>"
                +"<p>J2EE 邮件测试,<br />" +
                "<br />" +
                "   欢迎您，您已经注册成功。</p>" +
                "   <p>We'd like to thank you for your interest in our expert   network business. We appreciate you taking time to apply for membership in our   expert community.</p>" +
                "   <p>To ensure the integrity and quality of our network, we seek to verify the   credentials of our experts. We hope that you understand it. We will send you a   confirmation email shortly.</p>" +
                "   <p>Best regards,<br />" +
                "     <br />  Westlake International Team </p>  <p> </p>";
//        String SMTPHost = Servletconf.getInitParameter("smtphost");
//        String Port=Servletconf.getInitParameter("port");
//        String MailUsername = Servletconf.getInitParameter("mailusername");
//        String MailPassword = Servletconf.getInitParameter("mailpassword");
//        String MailFrom = Servletconf.getInitParameter("mailfrom");

        String SMTPHost = "smtp.126.com";
        String Port = "25";
        String MailUsername = "hcdstudio@126.com";
        String MailPassword = "alsldlhcd";
        String MailFrom = MailUsername;

//        if(SMTPHost==null||SMTPHost==""||MailUsername==null||MailUsername==""||MailPassword==null||MailPassword==""||MailFrom==null||MailFrom=="")
//        {
//            System.out.println("Servlet parameter Wrongs");
//        }
        EmailSender send=new EmailSender(SMTPHost,Port,MailUsername,MailPassword);
        if(send.sendingMimeMail(MailFrom, MailTo, MailCopyTo, MailBCopyTo, MailSubject, MailBody)){
            return true;
        }
        else
        {
            return false;
        }
    }
}
